source("COVID-pomp/scripts/graph_utils.R")
# Load data that has been produced
geodata <- read.csv("data/ch/geodata.csv")

files_filter <- list.files(path = "COVID-pomp/results/", pattern = "filtered_*")
cantons <- lapply(files_filter, function(s) unlist(strsplit(s, '_'))[3])

country <- st_read("data/ch/shp/swissBOUNDARIES3D_1_3_TLM_KANTONSGEBIET.shp")
## Reading layer `swissBOUNDARIES3D_1_3_TLM_KANTONSGEBIET' from data source `/Users/chadi/Documents/phd/COVID-19_CH/data/ch/shp/swissBOUNDARIES3D_1_3_TLM_KANTONSGEBIET.shp' using driver `ESRI Shapefile'
## Simple feature collection with 51 features and 20 fields
## geometry type:  POLYGON
## dimension:      XYZ
## bbox:           xmin: 485411 ymin: 75269.68 xmax: 833856.7 ymax: 295934
## z_range:        zmin: 193.51 zmax: 4613.729
## epsg (SRID):    21781
## proj4string:    +proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs
for (i in seq(nrow(country))) {
  country$ShortName[i] <- lapply(geodata['ShortName'][geodata$CantonNumber == country$KANTONSNUM[i],], as.character) # TODO hardcoded
}

ffilter <- list.files(path = "COVID-pomp/results/", pattern = glue("filtered_covid_*"), full.names = TRUE)

sims <- ffilter %>%
  map(readRDS) %>%    # read in all the files individually, using
  reduce(rbind)   

fdata <- list.files(path = "data/ch/cases/", pattern = glue("COVID19_Fallzahlen_Kanton_*"), full.names = TRUE)
data <- fdata %>%
  map(read_csv) %>%    # read in all the files individually, using
  reduce(bind_rows) %>% rename(ShortName = abbreviation_canton_and_fl)
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_logical(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_logical(),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_logical(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character(),
##   ncumul_confirmed_non_resident = col_double(),
##   ninst_hosp_non_resident = col_double()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character(),
##   ncumul_ICF = col_double(),
##   ninst_ICU_intub = col_double(),
##   ncumul_deceased_suspect = col_double()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_logical(),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_logical(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_logical(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_logical(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_logical(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_logical(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_logical(),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_logical(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character(),
##   TotalPosTests1 = col_double(),
##   ninst_ICU_intub = col_double()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_logical(),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character(),
##   TotalPosTests1 = col_double(),
##   TotalCured = col_double()
## )
states_to_plot <- c("tot_I", "Rt", "D")
filterstats <- compute_filterstats(sims)
fdata <- list.files(path = "data/ch/cases/", pattern = glue("COVID19_Fallzahlen_Kanton_*"), full.names = TRUE)
data <- fdata %>%
  map(read_csv) %>%    # read in all the files individually, using
  reduce(bind_rows) %>% 
  rename(ShortName = abbreviation_canton_and_fl)%>%
  select(-source, -ncumul_confirmed_non_resident, -ninst_hosp_non_resident, -ncumul_ICF,
         -ninst_ICU_intub, -ncumul_deceased_suspect, -TotalPosTests1, -TotalCured)
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_logical(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_logical(),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_logical(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character(),
##   ncumul_confirmed_non_resident = col_double(),
##   ninst_hosp_non_resident = col_double()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character(),
##   ncumul_ICF = col_double(),
##   ninst_ICU_intub = col_double(),
##   ncumul_deceased_suspect = col_double()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_logical(),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_logical(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_logical(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_logical(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_logical(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_logical(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_logical(),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_logical(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character(),
##   TotalPosTests1 = col_double(),
##   ninst_ICU_intub = col_double()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_logical(),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_double(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_logical(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_logical(),
##   ncumul_released = col_double(),
##   ncumul_deceased = col_double(),
##   source = col_character()
## )
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   time = col_time(format = ""),
##   abbreviation_canton_and_fl = col_character(),
##   ncumul_tested = col_double(),
##   ncumul_conf = col_double(),
##   ncumul_hosp = col_double(),
##   ncumul_ICU = col_logical(),
##   ncumul_vent = col_double(),
##   ncumul_released = col_logical(),
##   ncumul_deceased = col_double(),
##   source = col_character(),
##   TotalPosTests1 = col_double(),
##   TotalCured = col_double()
## )
data <- data %>% arrange(date) %>% group_by(ShortName) %>%
  mutate(cases = c(NA, diff(ncumul_conf)),
         deaths = c(NA, diff(ncumul_deceased)),
         cum_deaths = ncumul_deceased,
         hosp_curr = ncumul_hosp,
         discharged = c(ncumul_released[1], diff(ncumul_released)),
         delta_hosp = c(hosp_curr[1], diff(hosp_curr)),
         delta_ID = delta_hosp + discharged) %>%
  select(date, cases, deaths, cum_deaths, hosp_curr, discharged, delta_hosp, delta_ID) %>% 
  mutate(hosp_incid = NA)  %>%
  ungroup()
## Adding missing grouping variables: `ShortName`
plot_states(filterstats, data, "Rt")

for (ctn in cantons){
  print(plot_cnt_all(filterstats, data, ctn))
}
## Warning: Removed 97 rows containing missing values (geom_point).

## Warning: Removed 70 rows containing missing values (geom_point).

## Warning: Removed 89 rows containing missing values (geom_point).

## Warning: Removed 110 rows containing missing values (geom_point).

## Warning: Removed 156 rows containing missing values (geom_point).

## Warning: Removed 81 rows containing missing values (geom_point).

## Warning: Removed 121 rows containing missing values (geom_point).

## Warning: Removed 98 rows containing missing values (geom_point).

## Warning: Removed 50 rows containing missing values (geom_point).

## Warning: Removed 43 rows containing missing values (geom_point).

## Warning: Removed 124 rows containing missing values (geom_point).

## Warning: Removed 84 rows containing missing values (geom_point).

## Warning: Removed 111 rows containing missing values (geom_point).

## Warning: Removed 86 rows containing missing values (geom_point).

## Warning: Removed 56 rows containing missing values (geom_point).

## Warning: Removed 87 rows containing missing values (geom_point).

## Warning: Removed 63 rows containing missing values (geom_point).

## Warning: Removed 73 rows containing missing values (geom_point).

## Warning: Removed 75 rows containing missing values (geom_point).

## Warning: Removed 96 rows containing missing values (geom_point).

## Warning: Removed 169 rows containing missing values (geom_point).

## Warning: Removed 40 rows containing missing values (geom_point).

## Warning: Removed 77 rows containing missing values (geom_point).

## Warning: Removed 102 rows containing missing values (geom_point).

## Warning: Removed 76 rows containing missing values (geom_point).

## Warning: Removed 134 rows containing missing values (geom_point).

#a<- filterstats %>% filter(var == 'Rt') %>% group_by(ShortName) %>% arrange(time, .by_group = TRUE) %>%  mutate(pct_change = (mean/lead(mean) - 1) * 100) %>% ungroup()
#map <- inner_join(country, a %>% pivot_wider(pct_change, ), by="ShortName")